package tcp_net.mail.pop3.commands;

import tcp_net.mail.MailBoxFileManager;
import tcp_net.mail.pop3.commands.debug.DebugInfo;

import java.util.List;
import java.util.ArrayList;

/**
	This class provides a defined command to be executed
	@author J. Okuno
*/
public class USER extends POP3Command 
{
	/**
		A user account name
	*/
	private String name; 
	
	/**
		Init the class
		@param nm a user account name
		@param man a mailbox file manager
	*/
	public USER(String nm, MailBoxFileManager man) 
	{ 
		super(man);
		name = nm; 
	}
	
	/**	
		This method executes a defined command
		@return a list of reply messages in a string format
	*/
	public List<String> execute() 
	{
		//Search the user name
		boolean found = manager.addUserName(name);
		
		//found
		if(found)
		{
			reply = new POP3ReplyMessage(true, "name is a valid mailbox");
			reply_msgs.add(reply.execute().get(0));
		
			return reply_msgs;
		}
		
		//not found
		else
		{
			reply = new POP3ReplyMessage(false, "never heard of mailbox name");
			return reply.execute();
		}
	}
}